package com.zlx.rulemk.marketing.utils;

import com.typesafe.config.ConfigFactory;
import com.zlx.rulemk.marketing.constant.ConfigNames;
import org.apache.commons.lang.time.DateUtils;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author: zhanglingxing
 * @CreateTime: 2022-07-06
 * @Description: 获取flink 切分点工具类
 * @Version: 1.0
 *
 */
public class FlinkPointTimeUtils {

    public static long getFlinkPointTime(long timeStamp) {

        // TODO 1.需要考虑，flink程序刚上线或者停止下线在启动，会到时时间不准【后期优化】
        int flinkPointTime = ConfigFactory.load().getInt(ConfigNames.FLINK_POINT_TIME);

        // 给定时间向上取整，倒退2小时
        // 给定时间倒退2小时，然后向上取整
        Date dt = DateUtils.ceiling(new Date(timeStamp - flinkPointTime*60*60*1000), Calendar.HOUR);

        return dt.getTime();

    }
}
